<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@	page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midHostName" value='<%=ServerValue.getMidHostname()%>'/>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<link rel="Stylesheet" type="text/css" href="/css/jHtmlArea.css" />
<link rel="stylesheet" type="text/css" href="/css/jHtmlArea.ColorPickerMenu.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/css/ui.jqgrid.css" />
<link href="/css/ddaccordion.css" rel="stylesheet" type="text/css" media="screen" />
<style type="text/css" media="screen">
<!-- 
   select.selCont{ margin: 10px; width: 200px; }
-->
</style>
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<!-- html editor -->
<script type="text/javascript" src="/js/jHtmlArea-0.6.0.js"></script>
<script	src="/js/jHtmlArea.ColorPickerMenu-0.6.0.min.js"></script>
<script src="/js/grid.locale-en.js" type="text/javascript"></script>
<script src="/js/jquery.jqGrid.min.js" type="text/javascript" charset="UTF-8"></script>
<script src="/js/ckeditor/ckeditor.js" type="text/javascript"></script>
<s:url var="supplierPops" value="/json/supplierPops.do"/>
<s:url var="brandPops" value="/json/brandPops.do"/>
<script type="text/javascript"> 
	var content;
	var qry_target = '01';
	function dispScmNotice(){ 
		var notice = CKEDITOR.instances['scmNotice'];
		if(notice){
			notice.destroy();
			CKEDITOR.remove(notice);
		}
		CKEDITOR.replace('scmNotice',{toolbar : 'product'});
		CKEDITOR.config.contentsCss='/css/yaodian100_pdpagese_v2.css';
	}
	$(function() {
		<c-rt:if test="${not empty product.productId}">
 		if ( $("#supplierIdParam").val() != ""){
			$("#supplierIdParam").attr("readonly",true);
			$("#getSupplier").hide();
		}
		</c-rt:if>	
		<c-rt:if test="${empty product.productId}">	
		$("#isScmY").click(function() {
			$("#showScmNotice").show();
			dispScmNotice();
		});	 
		$("#isScmN").click(function() {
			var notice = CKEDITOR.instances['scmNotice'];
			if(notice){
				notice.destroy();
				CKEDITOR.remove(notice);
			}
			$("#showScmNotice").hide();
		});	 
		
		if ( $('#isScmN:checked').val() == 'N'){
			var notice = CKEDITOR.instances['scmNotice'];
			if(notice){
				notice.destroy();
				CKEDITOR.remove(notice);
			}
			$("#showScmNotice").hide();
		}else{
			$("#showScmNotice").show();
			dispScmNotice();
		}
		</c-rt:if>
		<c-rt:choose>
			<c-rt:when test="${not empty product.productId and product.isScm eq 'Y'}">
				$("#showScmNotice").show();
				dispScmNotice();
			</c-rt:when>
			<c-rt:otherwise>
				$("#showScmNotice").hide();
			</c-rt:otherwise>
		</c-rt:choose>
		$("#getSupplier").click(function() {
			doAR('${supplierPops}', 'dialog'); 
			openDialog('供应商搜寻',content, 550, 440);
		});	
		$("#getBrand").click(function() {
			doAR('${brandPops}', 'dialog'); 
			openDialog('品牌搜寻',content, 550, 440);
		});		
	 $("#loadingImg").dialog({
		  title: '资料载入中',
			bgiframe: true,
			autoOpen: false,
			height: 150,
			width:280,
			modal: true
		});		
	  $("#listPrice").numeric({allow:"."});
	  $("#prpsShelfPrice").numeric({allow:"."});
		$("#supplierIdParam").numeric();
		
		$("#submit_button").click(function(){
			var brief_result = true;
			if ($("#promoteName").val() == "" ){
				alert("请输入商品活动名称（副标）");
				return false;
			}
			if ( $("#promoteName").val() != "" ){
		    if(parseInt(GetCharLength($("#promoteName").val()),10)>40){
		    	alert("商品活动名称（副标）字数限制:20个中文字,40个英文字");
					return false;
		    }		
			}		
			if ($("#productName").val() == "" ){
				alert("请输入商品活动名称（主标）");
				return false;
			}
			if ( $("#mainCategory").text() == "" || $("#isEndNode").val() != "Y" ){
				alert("请选择最底层的目录");
				return false;
			}			
			if ( $("#productAttribute").val()  =="" ){
				alert("请选择销售状态");
				return false;
			}
			if ($("#listPrice").val() == "" ){
				alert("请输入廠商建議售價(市價)");
				return false;
			}
			if ( $("#supplierIdParam").val() == ""){
				alert("请选择供应商");
				return false;
			}
			if ( $("#supplierIdParam").val() == "010000" || $("#supplierIdParam").val() == "010001"){
				<c-rt:if test="${empty product.productId}">
					if ( $('input[name=isScm]:checked').val() == 'Y' ){
						alert("若供应商为万美供应商，采购模式不可为转单");
						return false;
					}
				</c-rt:if>
				<c-rt:if test="${not empty product.productId}">
					if ( "${product.isScm}" == "Y" ){
						alert("若供应商为万美供应商，采购模式不可为转单");
						return false;
					}
				</c-rt:if>
			}
			//if ( $("#brandIdParam").val() == ""){
			//	alert("请选择品牌");
				//return false;
			//}
			if ( $("#pm").val() == ""){
				alert("请选择主要负责PM");
				return false;
			}
			
			if ($("#organization").val() == ""){
				alert("请选择PM所属部门");
				return false;
			}			
			/*
			if ($("#prpsShelfPrice").val() == "" ){
				alert("请输入提报耀点价");
				$("#prpsShelfPrice").focus();
				return false;
			}	
			if ( parseFloat($("#prpsShelfPrice").val()) == 0.00){
				alert("提报耀点价不可等于0");
				$("#prpsShelfPrice").focus();
				return false;
			}
			*/		
			if( $("#brief").val() == ""){
				alert("请输入商品特色");
				return false;
			}else{
			 var xxx = $("#brief").val().length;
			 var k = 0;
			 for(var i = 0 ; i < xxx; i++ ){
				 if ( $("#brief").val().charAt(i) == "\n" ){
					 k++;
				 }
			 }
			 if ( k > 4 ){
				 alert("商品特色最多只能输入五行");
				 return false;
			 }
			 if ( k == 0 ){
				 if ( $("#brief").val().length > 30 ){
					 alert("商品特色第1行字数长度 超过30");
					 brief_result = false;
				 }
			 }else{
				 if ( $("#brief").val().indexOf("\n") != -1 ){
					 var briefArray = $("#brief").val().split("\n");
					 var ii = 0;
					 while( brief_result && ii < briefArray.length) {
						 ///alert(ii);
						 if ( briefArray[ii].length > 30 ){
							 alert("商品特色第" + (ii+1) + "行字数长度 超过30");
							 brief_result = false;
						 }
						 ii++;
					 }
				 }
			 }
			}			
			if ( brief_result == false) return false;
			
			var description = CKEDITOR.instances.description.getData();
			description = description.replace("<br />","");
			description = description.replace("<br>","");
			description = trim(description);
			if(description==""){
				alert("请输入商品描述");
				return false;
			}
			$("#description").val(description);
			var details = CKEDITOR.instances.details.getData();
			details = details.replace("<br />","");
			details = details.replace("<br>","");
			details = trim(details);
			if(details==""){
				alert("请输入規則參數");
				return false;
			}			
			$("#details").val(details);
			if(CKEDITOR.instances['scmNotice']){
				var scmNotice = CKEDITOR.instances.scmNotice.getData();
				scmNotice = scmNotice.replace("<br />","");
				scmNotice = scmNotice.replace("<br>","");
				scmNotice = trim(scmNotice);
				$("#scmNotice").val(scmNotice);
			}else{
				$("#scmNotice").val("");
			}					
			//if ( $('#isScmY:checked').val() == 'Y'){
				$.ajax({
				    url: '${midContextPath}/product/findSupplierApply.do',
				    type: 'post',
				    dataType: 'json',
				    data: {editsupplier:$("#supplierIdParam").val()},
				    cache: false,
				    success: function(spResult ){
				    	supplierCallback(spResult);
						}
				});
			//}else{
				//disabledBtn();
				//$("#productForm").submit();
			//}			
		});

		//load default value
		if ( "" != $("#tempCategoryPath").val()){ 
			var tempId = $("#tempCategoryPath").val().split("/");
			if ( $("#orderNotice").val() == "" )
				$.post("${midContextPath}/product/loadOrderNotice.do",{categoryId:tempId[0]},orderNoticeCallback,"json");
			$("#categorySelect").val(tempId[0]).attr("selected","selected");
			$("#mainCategoryId").val(tempId[tempId.length -1]);
			$.post("${midContextPath}/category/getProductCategory.do",{categoryid:tempId[0]},elementSelectCallback,"json");
		}
		//第0层
		$("#categorySelect").click(function(){
			if ( null != $(this).val()  ){
				<c-rt:if test="${empty product.productId}">
		    if ( $(this).val() == "1726" || $(this).val() == "1727" || $(this).val() == "1728" ){
		    	$('input[name=graphicType]').get(1).checked = true;
		    	$('input[name=graphicType]').get(0).checked = false;
		    }else{
		    	$('input[name=graphicType]').get(1).checked = false;
		    	$('input[name=graphicType]').get(0).checked = true;
		    }
		    </c-rt:if>
				$.post("${midContextPath}/pickProduct/loadOrderNotice.do",{categoryId:$(this).val()},orderNoticeCallback,"json");
				$.ajax({
				    url: '${midContextPath}/category/getProductCategory.do',
				    type: 'post',
				    dataType: 'json',
				    data: {categoryid:$(this).val(), callback: 'elementSelectCallback'},
				    cache: false,
				    beforeSend: function(xhr) {
							$("#loadingImg").dialog("open");
							$('#elementSelect').find('option').remove().end();
					   	$('#attributeSelect').find('option').remove().end();
					   	$('#itemSelect').find('option').remove().end();
					   	$('#unitSelect').find('option').remove().end();
					   	$('#listSelect').find('option').remove().end();						
				    },
				    complete:function(){
				    },
				    success: function( strData ){
				    	$("#loadingImg").dialog("close");
				    	elementSelectCallback(strData);
					}
				});
				$("#mainCategoryId").val($(this).val());
				$("#tempCategoryPath").val("");
			}
		});
		//第1层
		$("#elementSelect").click(function(){
			if ( null != $(this).val()  ){
				$.ajax({
				    url: '${midContextPath}/category/getProductCategory.do',
				    type: 'post',
				    dataType: 'json',
				    data: {categoryid:$(this).val(), callback: 'attributeSelectCallback'},
				    cache: false,
				    beforeSend: function(xhr) {
							$("#loadingImg").dialog("open");
							$('#attributeSelect').find('option').remove().end();
						  $('#itemSelect').find('option').remove().end();
						  $('#unitSelect').find('option').remove().end();
						  $('#listSelect').find('option').remove().end();						
				    },
				    success: function( strData ){
				    	$("#loadingImg").dialog("close");
				    	attributeSelectCallback(strData);
					}
				});		  	
				$("#mainCategoryId").val($(this).val());
				$("#tempCategoryPath").val("");
			}
		});
		//第2层
		$("#attributeSelect").click(function(){
			if ( null != $(this).val()  ){
				$.ajax({
				    url: '${midContextPath}/category/getProductCategory.do',
				    type: 'post',
				    dataType: 'json',
				    data: {categoryid:$(this).val(), callback: 'itemSelectCallback'},
				    cache: false,
				    beforeSend: function(xhr) {
							$("#loadingImg").dialog("open");
						  $('#itemSelect').find('option').remove().end();
						  $('#unitSelect').find('option').remove().end();
						  $('#listSelect').find('option').remove().end();						
				    },
				    success: function( strData ){
				    	$("#loadingImg").dialog("close");
				    	itemSelectCallback(strData);
					}
				});		  	
				$("#mainCategoryId").val($(this).val());
				$("#tempCategoryPath").val("");
			}
		});
		//第三层
		$("#itemSelect").click(function(){
			if ( null != $(this).val()  ){
				$.ajax({
				    url: '${midContextPath}/category/getProductCategory.do',
				    type: 'post',
				    dataType: 'json',
				    data: {categoryid:$(this).val(), callback: 'unitSelectCallback'},
				    cache: false,
				    beforeSend: function(xhr) {
							$("#loadingImg").dialog("open");
						  $('#unitSelect').find('option').remove().end();
						  $('#listSelect').find('option').remove().end();						
				    },
				    success: function( strData ){
				    	$("#loadingImg").dialog("close");
				    	unitSelectCallback(strData);
					}
				});				  	
				$("#mainCategoryId").val($(this).val());
				$("#tempCategoryPath").val("");
			}
		});
		//第四层
		$("#unitSelect").click(function(){
			if ( null != $(this).val()  ){
				$.ajax({
				    url: '${midContextPath}/category/getProductCategory.do',
				    type: 'post',
				    dataType: 'json',
				    data: {categoryid:$(this).val(), callback: 'listSelectCallback'},
				    cache: false,
				    beforeSend: function(xhr) {
							$("#loadingImg").dialog("open");
							$('#listSelect').find('option').remove().end();						
				    },
				    success: function( strData ){
				    	$("#loadingImg").dialog("close");
				    	listSelectCallback(strData);
					}
				});		  	
				$("#mainCategoryId").val($(this).val());
				$("#tempCategoryPath").val("");
			}
		});			
		//第五层
		$("#listSelect").click(function(){
			if ( null != $(this).val()  ){
				$("#mainCategoryId").val($(this).val());
				$("#tempCategoryPath").val("");
				combineCategoryPath();
				checkIsEndNodex();
			}
		}); 					
 	});
 	function disabledBtn(){
 		$("input[type='button']").each(function(){
			$(this).attr("disabled","disabled");
		});
 	}
	function supplierCallback(spResult){
		var rsVal = spResult.split(",");
		// 转单商品&非转单供应商=>alert 說明 & update 商品
		 if ( $('#isScmY:checked').val() == 'Y' || "${product.isScm}" == 'Y'){//轉單商品
			 if ( rsVal[0] == "false" ){
				alert("供应商发货资料不正确");
				return false;
			 }
			 if ( rsVal[1] == "N" ){
				alert("供应商不支援SCM");
				return false;
			 }
			 if ( rsVal[0] == "true" && rsVal[1] == "Y" ){
				 disabledBtn();
				 $("#productForm").submit();
			 } 
		 }else{// 轉單供應商&非轉單商品 要異動商品的轉單資料=>不理会
			 disabledBtn();
			 $("#productForm").submit();
		 }
	} 	
	//判断是否为最底层
 	function checkIsEndNodex(){
 		$.post("${midContextPath}/pickProduct/getJsonCategoryData.do",{mainCategoryId : $("#mainCategoryId").val()},endNodeCallback,"json");
 	}	
 	function endNodeCallback(categoryResult){
 			$("#isEndNode").val(categoryResult);
 	}

	 //去掉空格
	 function trim(str){
	    return str.replace(/(^\s*)|(\s*$)/g,"");
	 } 	

 	//购物须知ajax
	function orderNoticeCallback(jsonOrderNotice){
		CKEDITOR.instances.orderNotice.setData(jsonOrderNotice);
	}
	
	function elementSelectCallback(categories){
		if ( "" != $("#tempCategoryPath").val()){
			var tempId = $("#tempCategoryPath").val().split("/");
			for( var i = 0 ; i < categories.length; i++ ){
				var cmark='';
        		if(categories[i].isBrand=="Y"){
        			cmark=cmark+'○';//品牌
        		}
        		 if(categories[i].isPromotion=="Y"){
        			 cmark=cmark+'◎';//活動
        		}    
				if ( categories[i].id == tempId[1] ){
					$('#elementSelect').append($("<option selected='selected'></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
					$("#isEndNode").val(categories[i].isEndnode);
				}else
					$('#elementSelect').append($("<option></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
			}
			if ( tempId.length-1 > 1 ) $.post("${midContextPath}/category/getProductCategory.do",{categoryid:tempId[1]},attributeSelectCallback,"json");
		}else{
			for( var i = 0 ; i < categories.length; i++ ){
				var cmark='';
        		if(categories[i].isBrand=="Y"){
        			cmark=cmark+'○';//品牌
        		}
        		 if(categories[i].isPromotion=="Y"){
        			 cmark=cmark+'◎';//活動
        		}    
					$("#isEndNode").val(categories[i].isEndnode);
					$('#elementSelect').append($("<option></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
			}
		}
		combineCategoryPath();
		checkIsEndNodex();
	}
	function attributeSelectCallback(categories){
		if ( "" != $("#tempCategoryPath").val()){
			var tempId = $("#tempCategoryPath").val().split("/");
			for( var i = 0 ; i < categories.length; i++ ){
				var cmark='';
        		if(categories[i].isBrand=="Y"){
        			cmark=cmark+'○';//品牌
        		}
        		 if(categories[i].isPromotion=="Y"){
        			 cmark=cmark+'◎';//活動
        		}    
				if ( categories[i].id == tempId[2] ){
					$('#attributeSelect').append($("<option selected='selected'></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
					$("#isEndNode").val(categories[i].isEndnode);
				}else
					$('#attributeSelect').append($("<option></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
			}
			if ( tempId.length-1 > 2 ) $.post("${midContextPath}/category/getProductCategory.do",{categoryid:tempId[2]},itemSelectCallback,"json");
		}else{
			for( var i = 0 ; i < categories.length; i++ ){
				var cmark='';
        		if(categories[i].isBrand=="Y"){
        			cmark=cmark+'○';//品牌
        		}
        		 if(categories[i].isPromotion=="Y"){
        			 cmark=cmark+'◎';//活動
        		}    
					$("#isEndNode").val(categories[i].isEndnode);
					$('#attributeSelect').append($("<option></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
			}
		}
		combineCategoryPath();
		checkIsEndNodex();
	}
	function itemSelectCallback(categories){
		if ( "" != $("#tempCategoryPath").val()){
			var tempId = $("#tempCategoryPath").val().split("/");
			for( var i = 0 ; i < categories.length; i++ ){
				var cmark='';
        		if(categories[i].isBrand=="Y"){
        			cmark=cmark+'○';//品牌
        		}
        		 if(categories[i].isPromotion=="Y"){
        			 cmark=cmark+'◎';//活動
        		}    
				if ( categories[i].id == tempId[3] ) {
					$('#itemSelect').append($("<option selected='selected'></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
					$("#isEndNode").val(categories[i].isEndnode);
				}else
					$('#itemSelect').append($("<option></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
			}
			if ( tempId.length-1 > 3 ) $.post("${midContextPath}/category/getProductCategory.do",{categoryid:tempId[3]},unitSelectCallback,"json");
		}else{
			for( var i = 0 ; i < categories.length; i++ ){
				var cmark='';
        		if(categories[i].isBrand=="Y"){
        			cmark=cmark+'○';//品牌
        		}
        		 if(categories[i].isPromotion=="Y"){
        			 cmark=cmark+'◎';//活動
        		}    
					$("#isEndNode").val(categories[i].isEndnode);
					$('#itemSelect').append($("<option></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
			}
		}
		combineCategoryPath();
		checkIsEndNodex();
	}
	function unitSelectCallback(categories){
		if ( "" != $("#tempCategoryPath").val()){
			var tempId = $("#tempCategoryPath").val().split("/");
			for( var i = 0 ; i < categories.length; i++ ){
				var cmark='';
        		if(categories[i].isBrand=="Y"){
        			cmark=cmark+'○';//品牌
        		}
        		 if(categories[i].isPromotion=="Y"){
        			 cmark=cmark+'◎';//活動
        		}    
				if ( categories[i].id == tempId[4] ) {
					$('#unitSelect').append($("<option selected='selected'></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
					$("#isEndNode").val(categories[i].isEndnode);
				}else
					$('#unitSelect').append($("<option></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
			}
		}else{
			for( var i = 0 ; i < categories.length; i++ ){
				var cmark='';
        		if(categories[i].isBrand=="Y"){
        			cmark=cmark+'○';//品牌
        		}
        		 if(categories[i].isPromotion=="Y"){
        			 cmark=cmark+'◎';//活動
        		}    
					$("#isEndNode").val(categories[i].isEndnode);
					$('#unitSelect').append($("<option></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
			}
		}
		combineCategoryPath();
		checkIsEndNodex();
	}
	function listSelectCallback(categories){
		if ( "" != $("#tempCategoryPath").val()){
			var tempId = $("#tempCategoryPath").val().split("/");
			for( var i = 0 ; i < categories.length; i++ ){
				var cmark='';
        		if(categories[i].isBrand=="Y"){
        			cmark=cmark+'○';//品牌
        		}
        		 if(categories[i].isPromotion=="Y"){
        			 cmark=cmark+'◎';//活動
        		}    
				if ( categories[i].id == tempId[5] ) {
					$('#listSelect').append($("<option selected='selected'></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
					$("#isEndNode").val(categories[i].isEndnode);
				}else
					$('#listSelect').append($("<option></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
			}
		}else{
			for( var i = 0 ; i < categories.length; i++ ){
				var cmark='';
        		if(categories[i].isBrand=="Y"){
        			cmark=cmark+'○';//品牌
        		}
        		 if(categories[i].isPromotion=="Y"){
        			 cmark=cmark+'◎';//活動
        		}    
					$("#isEndNode").val(categories[i].isEndnode);
					$('#listSelect').append($("<option></option>").attr("value",categories[i].id).text(cmark+categories[i].name+'('+categories[i].id+')'));
			}
		}
		combineCategoryPath();
		checkIsEndNodex();
	}			
	//组合目录路径
	function combineCategoryPath(){
		var categoryTemp = $('#categorySelect option:selected').text(); 
		var elementTemp =  $('#elementSelect option:selected').text();
		var attributeTemp = $('#attributeSelect option:selected').text();
		var itemTemp = $('#itemSelect option:selected').text();
		var unitTemp = $('#unitSelect option:selected').text();
		var listTemp = $('#listSelect option:selected').text();
		var textTemp ;
		if ( "" != categoryTemp ) textTemp = categoryTemp;
		if ( "" != elementTemp ) textTemp = textTemp + " > " +  elementTemp;
		if ( "" != attributeTemp ) textTemp = textTemp + " > " +  attributeTemp;
		if ( "" != itemTemp ) textTemp = textTemp + " > " +  itemTemp;
		if ( "" != unitTemp ) textTemp = textTemp + " > " +  unitTemp;
		if ( "" != unitTemp ) textTemp = textTemp + " > " +  listTemp;
		$("#mainCategory").html(textTemp);
	}
	function GetCharLength(str)
	{
		var iLength = 0;
		for(var i = 0;i<str.length;i++)
			{
			if(str.charCodeAt(i) >255)
			{
				iLength += 2;
			}
			else
			{
				iLength += 1;
			}
		}
		return iLength;
	}
	function CutStr(Str,Len)
	{
		var CurStr = "";
		for(var i = 0;i<Str.length;i++)
			{
				CurStr += Str.charAt(i);
			if(GetCharLength(CurStr )>Len)
			{
				return Str.substring(0,i);
			}
		}
		return CurStr ;
	} 	
</script>
<style type="text/css">
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
<s:if test="hasActionErrors()">
	<s:actionerror cssClass="msg rn"/>
</s:if>
<s:if test="hasActionMessages()">
	<s:actionmessage cssClass="msg rn"/>
</s:if>
<p></p>
<h1>N选M商品管理<br />
<div class="f-link">
	<a href="${midContextPath}/pickProduct/search.do">回列表页</a>
</div>
</h1>
<c-rt:if test="${not empty product.productId or not empty shelf.shelfId}">
	<jsp:include page="commonMenu.jsp"/>
</c-rt:if>
<s:form action="saveProduct.do" method="post" id="productForm">
	<table class="tb-data" width="100%">
		<tr>
			<th>商品编号</th>			
			<td>
				<c-rt:choose>
					<c-rt:when test="${empty product.productId}">
					系统流水号发放
					</c-rt:when>
					<c-rt:otherwise>
						${product.productId}
						<img onError="this.src='/PImg/blank_75.gif'" src="/PImg/${fn:substring(product.productId,0,4)}/${product.productId}/${product.productId}_m75.jpg"/>
					</c-rt:otherwise>
				</c-rt:choose>
			</td>
	  </tr>		
		<tr>
			<th>* 商品活动名称（副标）</th>
			<td>
				<input type="text" name="promoteName" id="promoteName" size="50" maxlength="50"
				value="${shelf.promoteName}" /><span class="txt-rd">【※限20个中文字】</span>	    
			</td>
		</tr>
		<tr>
			<th>* 商品活动名称（主标）</th>
			<td>
				<input type="text" name="productName" id="productName" size="100"
				value="${product.productName}" />
			</td>
		</tr>
		  <tr>
			<th >	建立者<br/>
				建立日期<br/> 
					修改者<br/>
				修改日期
				</th><td>
					${product.createUser}<br/>
					<fmt-rt:formatDate value="${product.createDate}" pattern="yyyy-MM-dd HH:mm:ss" /><br/>
					${product.modifyUser}<br/>
				<fmt-rt:formatDate value="${product.modifyDate}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
	  	
	  </tr>
		<tr>
			<th>* 选择主分类</th>
			<td>
				<span class="txt-rd">○符号表示该分类为品牌;◎表活動</span><br/>
				<select id="categorySelect" name="categoryid" size="5" class="selCont">
         	<c-rt:forEach items="${rootCategories}" var="category">
						<option value="${category.id}">${category.name}(${category.id})</option>
					</c-rt:forEach>
        </select>       
        <select id="elementSelect" name="categoryid" size="5" class="selCont">            	
        </select>
        <select id="attributeSelect" name="categoryid" size="5" class="selCont">
        </select>
        <br/>
        <select id="itemSelect" name="categoryid" size="5" class="selCont">
        </select>
        <select id="unitSelect" name="categoryid" size="5" class="selCont">
        </select>
        <select id="listSelect" name="categoryid" size="5" class="selCont">
        </select>
        <br/>
                          主分类为：<span id="mainCategory"></span>
			</td>
		</tr>		
	  <tr>
	  	<th>*销售状态</th>
	  	<td>
	  		<s:select id="productAttribute" name="productAttribute" list="attributeMenu.options" listKey="key"  listValue="value.name" headerKey="" headerValue="---请选择销售状态---"/>
	  	</td>
	  </tr>
		<tr>
			<th>* 市价（厂商建议售价）</th>
			<td>
				<fmt-rt:formatNumber value="${product.listPrice}" pattern="#####0.0" var="listPrice"/>
				<input id="listPrice" name="listPrice" type="text" value="${listPrice}"/>
				<span class="txt-rd">【※市价小数点1位数后无条件舍去】</span>
			</td>
		</tr>	  
		<tr>
			<th>* 供应商</th>
			<td>
				<s:textfield name="supplierId" id="supplierIdParam" maxlength="6"/>
				<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" 
							id="getSupplier"/>
				<input type="text" id="supplierCompanyName" value="${supplierCompanyName}" readonly="readonly" size="60" style="border: 0px;"/>
			</td>
		</tr>
		<tr>
			<th>*采购模式</th>			
			<td>
				<c-rt:choose>
					<c-rt:when test="${not empty product.productId}">
						<c-rt:if test="${empty product.isScm or product.isScm eq 'N'}">入仓</c-rt:if>
						<c-rt:if test="${product.isScm eq 'B'}">BO</c-rt:if>
						<c-rt:if test="${product.isScm eq 'Y'}">SCM</c-rt:if>
					</c-rt:when>
					<c-rt:otherwise>
						<input id="isScmN" name="isScm" type="radio" value="N" <c-rt:if test="${empty product.isScm or product.isScm eq 'N'}">checked="checked"</c-rt:if>/>入仓
						<input id="isScmB" name="isScm" type="radio" value="B" <c-rt:if test="${product.isScm eq 'B'}">checked="checked"</c-rt:if>/>BO
        				<input id="isScmY" name="isScm" type="radio" value="Y" <c-rt:if test="${product.isScm eq 'Y'}">checked="checked"</c-rt:if>/>SCM
					</c-rt:otherwise>
				</c-rt:choose>
				<a href="${midContextPath}/images/scm.png" target="_blank">采购模式说明</a>
			</td>
		</tr>
	 	<tr>
			<th>*效期管理分类</th>
			<td>
				<s:select id="expireManage" name="expireManage" list="expireManageMenu.options" listKey="key"  listValue="value.name"/>
			</td>
		</tr>
		<tr>
			<th>是否需要防拆包材</th>
			<td>
				<input name="isAntiUnpacking" type="radio" value="Y" <c-rt:if test="${empty product.isAntiUnpacking or product.isAntiUnpacking eq 'Y'}">checked="checked"</c-rt:if>/>是
        <input name="isAntiUnpacking" type="radio" value="N" <c-rt:if test="${product.isAntiUnpacking eq 'N'}">checked="checked"</c-rt:if>/>否			
			</td>
		</tr>
		<tr>
			<th>购买时是否需验证码</th>			
			<td>
				<input name="isValidateNum" type="radio" value="Y" <c-rt:if test="${empty product.isValidateNum or product.isValidateNum eq 'Y'}">checked="checked"</c-rt:if>/>是
 	      <input name="isValidateNum" type="radio" value="N" <c-rt:if test="${product.isValidateNum eq 'N'}">checked="checked"</c-rt:if>/>否
			</td>
	  </tr>								 	
		<tr>
			<th>品牌</th>			
     		<td>
		     	<s:textfield name="editbrand" id="brandIdParam" />
			<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" 
				id="getBrand"/>  
				<input type="text" name="brandName" id="brandName" value="${brandName}" readonly="readonly" size="60" style="border: 0px;"/>
			</td>
	 	 </tr>
		<tr>
			<th>* 主要负责PM/PM所属单位</th>			
			<td>
				主要负责PM：<s:select id="pm" name="pm" list="users" listKey="username"  listValue="nameNative" headerKey="" headerValue="--请选择--"/>
				PM所属单位:<s:select id="organization" name="organization" list="groups" listKey="code"  listValue="description" headerKey="" headerValue="--请选择--"/>
			</td>
	  </tr>		
		<tr>
			<th>前台显示设定</th>
			<td>
				<table class="tb-1" width="100%">
					<thead>
						<tr><th>站首页</th></tr>
					</thead>
					<tbody>
						<tr>
							<td>
								<s:checkbox name="flag04" fieldValue="Y" value="%{flag04}">右侧本周推荐(tab 1)</s:checkbox>
								<s:checkbox name="flag05" fieldValue="Y" value="%{flag05}">右侧新鲜货(tab 2)</s:checkbox>
								<s:checkbox name="flag06" fieldValue="Y" value="%{flag06}">右侧热门话题(tab 3)</s:checkbox>
							</td>
						</tr>
					</tbody>
					<thead>
						<tr><th>分类页第2层以下</th></tr>
					</thead>				
					<tbody>
						<tr>
							<td>
								<s:checkbox name="flag16" fieldValue="Y" value="%{flag16}">馆长推荐</s:checkbox>
							</td>
						</tr>
					</tbody>
				</table>
			</td>
		</tr>	  	
		<tr>
	 		<th>提报耀点价</th>
	 		<td>
	 			<fmt-rt:formatNumber value="${product.prpsShelfPrice}" pattern="#####0.00" var="prpsShelfPrice"/>
				<input id="prpsShelfPrice" name="prpsShelfPrice" type="text" value="${prpsShelfPrice}"/>
				<span class="txt-rd">【※提报耀点价小数点2位数后无条件舍去】</span>
	    </td>
	 	</tr>
		<tr>
	 		<th>选择主档图显示类型</th>
	 		<td>
				<input name="graphicType" type="radio" value="S" <c-rt:if test="${product.graphicType eq 'S'}">checked="checked"</c-rt:if>/>方形图
		    <input name="graphicType" type="radio" value="R" <c-rt:if test="${product.graphicType eq 'R'}">checked="checked"</c-rt:if>/>长形图
		  </td>		
		</tr>	 		 			
		<tr>
			<th>* 商品特色</th>
			<td>
				<textarea id="brief" name="brief" cols="60" rows="5">${fileMap['brief']}</textarea>
			</td>
		</tr>
		<tr>
			<th>* 商品描述</th>
			<td>
				<textarea id="description" name=description cols="150" rows="30">${fileMap["description"]}</textarea>
				<script type="text/javascript">
				CKEDITOR.replace('description',{toolbar : 'product'});
				CKEDITOR.config.contentsCss = '/css/yaodian100_pdpagese_v2.css';
				</script>
			</td>
		</tr>
		<tr>
			<th>* 规则参数</th>
			<td>
				<textarea id="details" name="details" cols="150" rows="30">${fileMap["details"]}</textarea>
				<script type="text/javascript">
					CKEDITOR.replace('details',{toolbar : 'product'});
					CKEDITOR.config.contentsCss = '/css/yaodian100_pdpagese_v2.css';
				</script>
			</td>
		</tr>
		<tr>
			<th>购物须知<br/>（若不填会带入该馆预设内容）</th>
			<td>
				<textarea id="orderNotice" name="orderNotice" cols="150" rows="30">${fileMap["orderNotice"]}</textarea>
				<script type="text/javascript">
				CKEDITOR.replace('orderNotice',{toolbar : 'product'});
				CKEDITOR.config.contentsCss = '/css/yaodian100_pdpagese_v2.css';
				</script>
			</td>
		</tr>	
			<tr id="showScmNotice">
				<th>特殊商品购物须知</th>
				<td colspan="3">
					<textarea id="scmNotice" name="scmNotice" cols="150" rows="30">${fileMap["scmNotice"]}</textarea>
				</td>
			</tr>			  
		<tr>
			<td colspan="2">
			<input type="hidden" name="productIdParam" value="${product.productId}" />
			<input type="hidden" name="shelfIdParam" value="${shelf.shelfId}" />
			<input type="hidden" id="isEndNode" name="isEndNode"/>
			<input type="hidden" id="tempCategoryPath" name="tempCategoryPath" value="${categoryPath}"/>
			<input type="hidden" id="mainCategoryId" name="mainCategoryId" value="${product.mainCategoryID}" />
			<input type="button" id="submit_button" value="储存商品" /> 
			<input type="button" onclick="this.form.action='search.do';this.form.submit();"	value="Cancel" />
			<input type="hidden" id="spResult"/>
			</td>
		</tr>
	</table>
</s:form>
<div id="loadingImg" style="display:none;">
	<img src="/images/loading.gif"/>资料载入中,请稍候...
</div>